import Vue from 'vue'
import Vuex from 'vuex'
import {getItem, setItem} from "@/plugins";
const tokenKey = 'access_key'
const user = 'user'
const userInfo = 'userInfo'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: getItem(tokenKey),
    lang:'',

  },
  getters: {
  },
  mutations: {
    // 更新token
    saveToken(state, data) {
      state.token = data.token
      state.User = data
      setItem(tokenKey, state.token)
    },

  },
  actions: {
    loginSetToken({commit}, data) {
      return new Promise((resolve, reject) => {
        // userLoginInterface(data).then(res => {
        //   commit('saveToken', res)
        //   Message.success('账号登录成功')
        //   resolve(res)
        // }).catch(err => {
        //   reject(err)
        // })
      })
    },
    // 调用例子
    // this.$store.dispatch('loginSetToken',this.submitForm).then(res=>{
    //   this.interfaceLoading=false
    //   this.$router.replace('/home/chat')
    // }).catch(err=>{
    //   this.interfaceLoading=false
    //   this.verificationCode()
    // })
  },
  modules: {
  }
})
